<template>
	<view>
		<view class="message-list-item u-p-30 u-white-bg" v-for="(item,index) in list" :key="index"
			@click="toSystemMsg(item)">
			<view class="message-icon">
				<u-avatar src="/static/icons/message-icon.png" mode="circle"></u-avatar>
				<u-badge :is-dot="true" :offset="[5, 5]" :count="item.isRead==0?1:0">
				</u-badge>
			</view>
			<view class="message-content">
				<view class="message-type-title">
					<view class="u-flex-1">
						{{item.title}}
					</view>
					<view class="message-time"></view>
				</view>
				<view class="message-item u-line-1">
					{{item.creatorUser}}
				</view>
				<view>
					{{$u.timeFormat(item.lastModifyTime, 'yyyy-mm-dd')}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentPage: 1,
				list: [],
				total: -1
			}
		},
		methods: {
			loadData() {
				if (this.total !== this.list.length) {
					this.$u.api.getMessage({
						type: '2',
						pageSize: 20,
						currentPage: this.currentPage
					}).then(res => {
						this.total = res.pagination.total
						if (this.currentPage == 1) {
							this.list = res.list
						} else {
							this.list.push(...res.list)
						}
					}).catch(err => {
						console.error(err)
					})
				}
			},
			toSystemMsg(item) {
				// console.log(item)
				this.$u.route('pages/work/flowchart/backlog')
			}
		},
		onShow() {
			this.list = []
			this.loadData()
		},
		onReachBottom() {
			this.currentPage++
			this.loadData()
		}
	}
</script>

<style lang="scss" scoped>
	.message-list-item {
		display: flex;
		margin-bottom: 20rpx;

		.message-icon {
			position: relative;
			width: 88rpx;
			height: 88rpx;
		}

		.message-content {
			flex: 1;
			width: 0;
			padding-left: 20rpx;
			border-bottom: 1px solid #F7F8FA;

			.message-type-title {
				display: flex;
				font-size: 32rpx;
				font-weight: bold;

				.message-time {
					width: 100rpx;
					text-align: center;
					font-size: 24rpx;
					color: #CCCCCC;
				}
			}

			.message-item {
				width: 100%;
				padding-bottom: 20rpx;
				font-size: 24rpx;
				color: #999999;
			}
		}
	}
</style>
